function residual = dynamic_resid(T, y, x, params, steady_state, it_, T_flag)
% function residual = dynamic_resid(T, y, x, params, steady_state, it_, T_flag)
%
% File created by Dynare Preprocessor from .mod file
%
% Inputs:
%   T             [#temp variables by 1]     double   vector of temporary terms to be filled by function
%   y             [#dynamic variables by 1]  double   vector of endogenous variables in the order stored
%                                                     in M_.lead_lag_incidence; see the Manual
%   x             [nperiods by M_.exo_nbr]   double   matrix of exogenous variables (in declaration order)
%                                                     for all simulation periods
%   steady_state  [M_.endo_nbr by 1]         double   vector of steady state values
%   params        [M_.param_nbr by 1]        double   vector of parameter values in declaration order
%   it_           scalar                     double   time period for exogenous variables for which
%                                                     to evaluate the model
%   T_flag        boolean                    boolean  flag saying whether or not to calculate temporary terms
%
% Output:
%   residual
%

if T_flag
    T = modelG.dynamic_resid_tt(T, y, x, params, steady_state, it_);
end
residual = zeros(20, 1);
lhs = params(1)*y(12);
rhs = params(4)*(1-params(3))*y(10)+y(16)*params(3)*T(1)*(-params(13))*(1-T(1))+(params(1)-params(4)*(1-params(3)))*y(21);
residual(1) = lhs - rhs;
lhs = (1-params(1))*y(13);
rhs = (1-params(3))*(1-params(4))*y(11)+y(16)*T(1)*params(3)*params(13)*(1-T(1))+y(21)*params(3)*(1-T(1));
residual(2) = lhs - rhs;
lhs = params(11)*y(14);
rhs = params(11)*params(9)*y(27)+(1-params(11))*(1-params(11)*params(9))*(y(21)*params(7)+y(12)*params(8)-y(16)*(1-T(1)));
residual(3) = lhs - rhs;
lhs = params(12)*y(15);
rhs = params(9)*params(12)*y(28)+(1-params(12))*(1-params(9)*params(12))*(y(21)*params(7)+y(13)*params(8)+T(1)*y(16));
residual(4) = lhs - rhs;
residual(5) = params(10)*y(26)-params(14)*y(20);
lhs = y(21)*params(7);
rhs = params(7)*y(29)-(y(20)-y(30));
residual(6) = lhs - rhs;
lhs = y(26);
rhs = T(1)*y(14)+y(15)*(1-T(1));
residual(7) = lhs - rhs;
lhs = y(19);
rhs = params(1)*y(14)+(1-params(1))*y(15);
residual(8) = lhs - rhs;
lhs = y(17);
rhs = params(1)*y(12)+(1-params(1))*y(13);
residual(9) = lhs - rhs;
lhs = y(18);
rhs = params(4)*y(10)+(1-params(4))*y(11);
residual(10) = lhs - rhs;
lhs = y(16);
rhs = y(14)+y(3)-y(15);
residual(11) = lhs - rhs;
lhs = y(8);
rhs = params(5)*y(1)+params(15)*x(it_, 1);
residual(12) = lhs - rhs;
lhs = y(9);
rhs = params(6)*y(2)+params(16)*x(it_, 2);
residual(13) = lhs - rhs;
lhs = y(10);
rhs = y(8)*0.16;
residual(14) = lhs - rhs;
lhs = y(11);
rhs = y(9)*0.16;
residual(15) = lhs - rhs;
lhs = y(7);
rhs = y(8)+y(9);
residual(16) = lhs - rhs;
lhs = y(15);
rhs = y(23)-y(5);
residual(17) = lhs - rhs;
lhs = y(14);
rhs = y(24)-y(6);
residual(18) = lhs - rhs;
lhs = y(26);
rhs = y(22)-y(4);
residual(19) = lhs - rhs;
lhs = y(25);
rhs = y(18)*params(2);
residual(20) = lhs - rhs;

end
